﻿namespace Mp3Observer.Common.IoC
{
    using System.Configuration;

    /// <summary>
    /// ConfigurationElementCollection for ctors; needed to define the key element (Dependency) of the collection.
    /// </summary>
    [ConfigurationCollection(typeof(ConstructorElement))]
    public class ConstructorCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// Gets the <see cref="ConstructorElement"/> with the specified idx.
        /// </summary>
        /// <param name="idx">collection index</param>
        /// <value></value>
        public ConstructorElement this[int idx]
        {
            get { return (ConstructorElement)BaseGet(idx); }
        }

        /// <summary>
        /// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </summary>
        /// <returns>
        /// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new ConstructorElement();
        }

        /// <summary>
        /// Gets the element key for a specified configuration element when overridden in a derived class.
        /// </summary>
        /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
        /// <returns>
        /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ConstructorElement)element).Dependency;
        }
    }
}
